/**
 * 打卷库存表
 */

//库存表
$(function () {

// $.parser.parse();  //重新加载一下页面样式   有时候easyui-datagrid页面显示不出来
    btn_refresh();
    getsum();

    $('#kcdetail').datagrid({
        onDblClickRow: function (rowIndex) {//鼠标双击事件
            console.log('进入双击事件');
            var currentRow = $("#kcdetail").datagrid("getSelected");//获得选中行的信息
            let bpgg=currentRow.b_firstgg;
            let ylgg=currentRow.b_ylgg;
            let pm=currentRow.b_pinming;
            let pc=currentRow.b_batch;
            $('#A').window('open');
            getbarcodedetail(bpgg,ylgg,pm,pc);
        }
    });

    $('#A').window('close');

});

function sx() {
    btn_refresh();
    getsum();

}

//刷新
function btn_refresh() {

    $.ajax({
        url: strLin + '/jrk/inv' ,
        type: 'get',
        dataType: 'json',
        success: function (cdata) {
            let data=cdata.data;
            console.log(data);
            $('#kcdetail').datagrid('loadData', data);
            $('#kcdetailA').datagrid('loadData', data);
// $.parser.parse();  //重新加载一下页面样式   有时候easyui-datagrid页面显示不出来
        }

    });
}

//合计
function  getsum() {
    //扫码发货页面网格数据汇总
    $('#kcdetail').datagrid({
        showFooter: true,
        onLoadSuccess: function (data) {
            data = data.rows;
            var qty = 0;
            var ps=0;

            for (let i = 0; i < data.length; i++) {
                qty += data[i].qty ? parseFloat(data[i].qty) : 0;
                ps += data[i].ps ? parseFloat(data[i].ps) : 0;
            }
            console.log(qty);
            $(this).datagrid('reloadFooter', [{
                b_dingdanhao: '合计',
                qty: qty.toFixed(1),
                ps: ps,
            }])
        }
    });
}


//根据 原料规格、白坯规格、品名 获取对应的打卷数和计划信息  2021-4-16 08:57:17 OK
function getbarcodedetail(gg1,gg2,pm,pc) {
    if (gg1 == undefined) {gg1=""}
    if (gg2 == undefined) {gg2=""}
    if (pm == undefined) {pm=""}
    if (pc == undefined) {pc=""}
    var str={"gg1":gg1,"gg2":gg2,"goodsname":pm,"pc":pc};
    console.log(str);

    $.ajax({

        // usp_getJRKDetail_gg  该链接执行的存储过程 三个参数
        // url: strLin+'/jrk/invgg',

        url: strLin+'/jrk/invgg4',
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(str),
        contentType: "application/json;charset=UTF-8",
        success: function (cData) {
            console.log(cData);
            let data = cData.data;
            $('#kcdetailA').datagrid('loadData', data);
            console.log(data);
            getsumA();

        }, complete: function (XMLHttpRequest, textStatus) {
            console.log("进入到complete");
        }

    })
}

function  getsumA() {
    //扫码发货页面网格数据汇总
    $('#kcdetailA').datagrid({
        showFooter: true,
        onLoadSuccess: function (data) {
            data = data.rows;
            var qty = 0;
            var ps=0;

            for (let i = 0; i < data.length; i++) {
                qty += data[i].B_GJ ? parseFloat(data[i].B_GJ) : 0;
                ps =i+1;
            }

            $(this).datagrid('reloadFooter', [{
                b_clientname: '合计',
                B_GJ: qty.toFixed(1),
                B_AorB: ps,
            }])
        }
    });
}

//关闭当前标签页事件
function closeTab() {
    window.parent.closeTab();
}

/*****************************************************/

/*设置时间格式*/
function add0(m) {
    return m < 10 ? '0' + m : m
}

function format(shijianchuo) {
    //shijianchuo是整数，否则要parseInt转换
    var time = new Date(shijianchuo);
    var y = time.getFullYear();
    var m = time.getMonth() + 1;
    var d = time.getDate();
    var h = time.getHours();
    var mm = time.getMinutes();
    var s = time.getSeconds();
    return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
}

//获取日期
function getDate(param) {
    if (isNaN(param)) {
        param = 0;
    }
    var curDate = new Date();
    var newDate = new Date(curDate);
    newDate.setDate(curDate.getDate() + param);
    var year = newDate.getFullYear();
    var month = newDate.getMonth() + 1 < 10 ? '0' + (newDate.getMonth() + 1) : newDate.getMonth() + 1;
    var date = newDate.getDate() < 10 ? '0' + newDate.getDate() : newDate.getDate();
    var separator = '-';
    return year + separator + month + separator + date;
}
/****************************************************/